import 'package:flutter/material.dart';

/// @date 2020/08/06  10:59
/// @author 程志强
/// @des 手势竞争

class GestureBothDirection extends StatefulWidget {
  @override
  _GestureBothDirectionState createState() => _GestureBothDirectionState();
}

class _GestureBothDirectionState extends State<GestureBothDirection> {
  // 距离顶部的偏移
  double _top = 0.0;

  // 距离左边的偏移
  double _left = 0.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("手势竞争"),
      ),
      body: Stack(
        children: <Widget>[
          Positioned(
            top: _top,
            left: _left,
            child: GestureDetector(
              child: CircleAvatar(
                child: Text("A"),
              ),
              onVerticalDragUpdate: (DragUpdateDetails e) {
                setState(() {
                  _top += e.delta.dy;
                });
              },
              onHorizontalDragUpdate: (DragUpdateDetails d) {
                setState(() {
                  _left += d.delta.dx;
                });
              },
            ),
          )
        ],
      ),
    );
  }
}
